const url = require("url")

// 解析url

var str = "http://localhost:3000/api/register?user=admin&pass=1234";

console.log(str);

// 将字符的url解析成对象
console.log(url.parse(str));

console.log(url.parse(str, true));

// 将对象的url解析成字符
var obj = {
    protocol: 'http:',
    slashes: true,
    auth: null,
    host: 'localhost:3000',
    port: '3000',
    hostname: 'localhost',
    hash: null,
    search: '?user=admin&pass=1234',
    query: { user: 'admin', pass: '1234' },
    pathname: '/api/register',
    path: '/api/register?user=admin&pass=1234',
    href: 'http://localhost:3000/api/register?user=admin&pass=1234'
}
console.log(url.format(obj));